// pages/findowerns/findowerns.js
//引入请求代码
var call = require("../../utils/ajax.js")
var that;
let ol = 0;
// var ImgURL = "";

Page({

    /**
     * 页面的初始数据
     */
    data: {
        currentData: 0,
        catList: [{
                name: '埃及猫'
            }, {
                name: '阿比西尼亚猫'
            }, {
                name: '奥西猫'
            }, {
                name: '布偶猫'
            }, {
                name: '波斯猫'
            }, {
                name: '伯曼猫'
            }, {
                name: '巴厘猫'
            }, {
                name: '豹猫'
            }, {
                name: '东方猫'
            }, {
                name: '东奇尼猫'
            }, {
                name: '短毛猫'
            }, {
                name: '哈瓦那猫'
            }, {
                name: '虎皮猫'
            }, {
                name: '卷毛猫'
            }, {
                name: '金吉拉'
            }, {
                name: '加菲猫'
            }, {
                name: '柯尼斯卷毛猫'
            }, {
                name: '卡拉猫'
            }, {
                name: '蓝猫'
            }, {
                name: '褴褛猫'
            }, {
                name: '美短'
            },
            {
                name: '孟买猫'
            }, {
                name: '缅甸猫'
            }, {
                name: '缅因猫'
            }, {
                name: '马恩岛猫'
            }, {
                name: '美国刚毛猫'
            }, {
                name: '美国卷毛猫'
            }, {
                name: '挪威森林猫'
            }, {
                name: '日本短尾猫'
            }, {
                name: '萨凡纳猫'
            }, {
                name: '斯芬克斯猫'
            }, {
                name: '沙特尔猫'
            }, {
                name: '狮子猫'
            }, {
                name: '土耳其梵猫'
            }, {
                name: '新加坡猫'
            }, {
                name: '英短'
            }, {
                name: '折耳'
            }, {
                name: '中华田园猫'
            },
        ],
        doglList: [{
                name: '澳牧'
            },
            {
                name: '艾力梗'
            }, {
                name: '阿拉斯加'
            }, {
                name: '爱尔兰雪达犬'
            }, {
                name: '爱尔兰红白雪达犬'
            }, {
                name: '阿纳托利亚牧羊犬'
            }, {
                name: '爱尔兰猎狼犬'
            }, {
                name: '爱斯基摩犬'
            }, {
                name: '阿富汗'
            }, {
                name: '阿芬平斯澈犬'
            }, {
                name: '澳洲丝毛梗'
            }, {
                name: '爱尔兰挭'
            }, {
                name: '澳大利亚梗'
            }, {
                name: '爱尔兰水猎犬'
            }, {
                name: '边牧'
            }, {
                name: '博美'
            }, {
                name: '比熊'
            }, {
                name: '博瑞犬'
            }, {
                name: '波音达'
            }, {
                name: '伯恩山犬'
            }, {
                name: '波索尔'
            }, {
                name: '比牧'
            }, {
                name: '巴西菲斯犬'
            }, {
                name: '比利牛斯獒犬'
            }, {
                name: '比特犬'
            }, {
                name: '捕鼠梗'
            }, {
                name: '波士顿梗'
            }, {
                name: '比格'
            }, {
                name: '巴哥'
            }, {
                name: '边境梗'
            }, {
                name: '波登可葡萄牙梅迪奥犬'
            },
            {
                name: '玛利诺犬'
            },
            {
                name: '北海道犬'
            },
            {
                name: '冰岛牧羊犬'
            },
            {
                name: '波低牧犬'
            },
            {
                name: '巴吉度'
            },
            {
                name: '布里塔尼犬'
            },
            {
                name: '贝灵顿梗'
            },
            {
                name: '波利'
            },
            {
                name: '查理王'
            },
            {
                name: '长须牧'
            },
            {
                name: '查尔斯骑士王小牧犬'
            },
            {
                name: '中华田园犬'
            },
            {
                name: '川东猎犬'
            },
            {
                name: '柴犬'
            },
            {
                name: '德牧'
            },
            {
                name: '大丹'
            }, {
                name: '杜高'
            }, {
                name: '德国刚毛指示犬'
            }, {
                name: '德国短毛'
            }, {
                name: '大白熊'
            }, {
                name: '杜宾'
            }, {
                name: '巨型雪纳瑞'
            }, {
                name: '大麦町'
            }, {
                name: '短毛猎狐梗'
            }, {
                name: '狐狸犬'
            }, {
                name: '丹迪丁蒙梗'
            }, {
                name: '俄罗斯牧羊犬'
            }, {
                name: '法国狼犬'
            }, {
                name: '法老王猎犬'
            }, {
                name: '法斗'
            },
            {
                name: '泰迪'
            }, {
                name: '哥顿雪达'
            }, {
                name: '古牧'
            }, {
                name: '高加索'
            }, {
                name: '格里芬犬'
            }, {
                name: '哈士奇'
            }, {
                name: '红骨猎浣熊犬'
            }, {
                name: '哈威那'

            }, {
                name: '湖畔梗'
            }, {
                name: '蝴蝶犬'
            }, {
                name: '荷兰毛狮犬'
            }, {
                name: '惠比特'
            }, {
                name: '捷克狼犬'
            }, {
                name: '吉娃娃'
            }, {
                name: '杰克罗素'
            }, {
                name: '加那利'
            }, {
                name: '金毛'
            }, {
                name: '京巴'
            }, {
                name: '库维斯犬'
            }, {
                name: '卡斯罗'
            }, {
                name: '可蒙犬'
            }, {
                name: '凯恩'
            }, {
                name: '斯凯梗犬'
            }, {
                name: '柯基'
            }, {
                name: '卡迪根柯基'
            }, {
                name: '可卡（美国）'
            }, {
                name: '可卡（英国）'
            }, {
                name: '凯利蓝'
            }, {
                name: '昆明犬'
            }, {
                name: '克伦伯猎鹬犬'
            }, {
                name: '灵缇'
            }, {
                name: '罗得西亚犬'
            }, {
                name: '罗威纳'
            }, {
                name: '罗威士挭'
            }, {
                name: '猎狐梗'
            }, {
                name: '拉萨犬'
            }, {
                name: '腊肠'
            }, {
                name: '拉布拉多'
            }, {
                name: '迷你雪纳瑞'
            }, {
                name: '美国猎狐犬'
            }, {
                name: '马士提夫犬'
            }, {
                name: '马耳济斯'
            }, {
                name: '曼彻斯特'
            }, {
                name: '迷你牛头梗'
            }, {
                name: '迷你杜宾'
            }, {
                name: '美系秋田'
            }, {
                name: '美国水猎犬'
            }, {
                name: '纽波利顿'
            }, {
                name: '纽芬兰'
            }, {
                name: '挪威猎麋犬'
            }, {
                name: '牛头梗'
            }, {
                name: '帕特大勒梗'
            }, {
                name: '葡萄牙波登可犬'
            }, {
                name: '葡萄牙水犬'
            }, {
                name: '平毛寻回猎犬'
            }, {
                name: '葡萄牙牧羊犬'
            }, {
                name: '秋田'
            }, {
                name: '拳师'
            }, {
                name: '切萨皮克'
            }, {
                name: '日本狆犬'
            }, {
                name: '软毛麦色梗'
            }, {
                name: '萨摩耶'
            }, {
                name: '史宾诺'
            }, {
                name: '萨卢基犬'
            }, {
                name: '苏联红'
            }, {
                name: '苏牧'
            }, {
                name: '圣伯纳'
            }, {
                name: '苏格兰梗'
            }, {
                name: '舒伯齐犬'
            }, {
                name: '史宾格（威尔士）'
            }, {
                name: '斯科舍'
            }, {
                name: '沙皮'
            }, {
                name: '史宾格（英国）'
            }, {
                name: '斯塔福'
            }, {
                name: '松狮'
            }, {
                name: '土佐犬'
            }, {
                name: '魏玛犬'
            }, {
                name: '细犬'
            },
            {
                name: '寻血猎犬'
            },
            {
                name: '维斯拉犬'
            },
            {
                name: '小鹿犬'
            },
            {
                name: '西施'
            },
            {
                name: '西里汉挭'
            },
            {
                name: '西高地'
            },
            {
                name: '雪纳瑞'
            },
            {
                name: '西藏牧犬'
            },
            {
                name: '西藏梗'
            },
            {
                name: '下司犬'
            },
            {
                name: '喜乐蒂'
            },
            {
                name: '英国雪达'
            },
            {
                name: '英国猎狐犬'
            },
            {
                name: '意大利灵缇'
            }, {
                name: '约克夏'
            },
            {
                name: '银狐'
            },
            {
                name: '英斗'
            },
            {
                name: '中亚牧羊犬'
            },
            {
                name: '藏獒'
            },
            {
                name: '中国冠毛'
            }
        ],
        petItems: [{
                name: '喵星人',
                value: '喵星人',
            },
            {
                name: '汪星人',
                value: '汪星人',
            }
        ],
        sexItems: [{
                name: '男孩子',
                value: '男孩子',
            },
            {
                name: '女孩子',
                value: '女孩子',
            },
        ],
        images: [],
        uploadedImages: [],
        ImgURL: "",
        search_pet_name: "",
        search_pet_age: "",
        // search_pet_contact: "",
        search_pet_message: "",
        search_pet_area: "",
        publisher_phone: "",
        lose_time: "",
        lose_city_area: "",
        search_pet_sex: "",
        lose_county_area: "",
        lose_detailed_area: "",
        special_advice: ""
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {

    },

    radio: function(e) {

        var index = e.currentTarget.dataset.index; //获取当前点击的下标
        var petItems = this.data.petItems; //选项集合
        var sexItems = this.data.sexItems;
        if (petItems[index].checked) return; //如果点击的当前已选中则返回
        petItems.forEach(item => {
            item.checked = false
        })
        petItems[index].checked = true; //改变当前选中的checked值
        this.setData({
            petItems: petItems
        });


    },
    bindPickerChange: function(e) {
        var that = this;
        that.setData({
            value: that.data.catList[e.detail.value].name,
            Index: e.detail.value
        })
        console.log('picker发送选择改变，携带值为', that.data.catList[e.detail.value].name)
    },
    bindPickerChange1: function(e) {
        var that = this;
        that.setData({

            value: that.data.doglList[e.detail.value].name,
            Index: e.detail.value
        })
        console.log('picker发送选择改变，携带值为', that.data.doglList[e.detail.value].name)
    },
    radio_sex: function(e) {
        var index = e.currentTarget.dataset.index;
        var sexItems = this.data.sexItems;
        if (sexItems[index].checked) return; //如果点击的当前已选中则返回
        sexItems.forEach(item => {
            item.checked = false
        })
        sexItems[index].checked = true; //改变当前选中的checked值
        this.setData({
            sexItems: sexItems
        });
    },

    radioChange: function(e) {
        var checkValue = e.detail.value;
        this.setData({
            checkValue: checkValue
        });
        console.log(checkValue)
        var that = this
        if (checkValue == '喵星人') {
            that.setData({
                hideAdd: 0
            })
        } else {
            that.setData({
                hideAdd: 1
            })
        }

    },
    radioChange_sex: function(e) {
        var checkValue_sex = e.detail.value;
        this.setData({
            checkValue_sex: checkValue_sex
        });
        console.log(checkValue_sex)
    },
    sendImg: function(imgurl) {


    },
    chooseImage: function() {
        // 选择图片
        var that = this
        wx.chooseImage({
            count: 1, // 默认9
            sizeType: ['compressed'],
            sourceType: ['album', 'camera'],
            // 可以指定来源是相册还是相机，默认二者都有
            success: function(res) {
                // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
                var tempFilePaths = res.tempFilePaths;
                let kla = false;

                function admin(tempFilePaths) {
                    console.log("ss");
                    ol = ol + 1;
                    if (ol == 3) {
                        console.log("ss")
                        kla = true
                    } else {
                        console.log("ss")
                        kla = false
                    }
                    return tempFilePaths;
                }
                let ddd = admin(tempFilePaths);
                console.log(ol);
                that.setData({
                    images: that.data.images.concat(ddd),
                    kk: kla
                });
            }
        })

    },
    sendSearch: function(data) {
        // let 
        call.request1(url, postData, function(res) {

        }, function(e) {

        })
    },

    test: function() {
        let kk = this.data.images;
        this.sendImg(kk);
    },
    // 图片预览
    previewImage: function(e) {
        //console.log(this.data.images);
        var current = e.target.dataset.src
        wx.previewImage({
            current: current,
            urls: this.data.images
        })
    },
    delete: function(e) {
        let kk = this;
        var index = e.currentTarget.dataset.index;
        var images = this.data.images;
        images.splice(index, 1);
        this.setData({
            images: images
        });
        ol = ol - 1;
        if (ol != 3) {
            kk.setData({
                kk: false
            })
        }
        console.log(ol)
    },
    up: function() {
      console.log("执行到了")
        let FileName = "";
        FileName = wx.getStorageSync('fileName');
        console.log(FileName)
        let that = this;
        let kk = this.data.images;
        // let fileName = "null";
        let url = 'Img/addImg?className=searchMan&fileName=null';
        // if (FileName != undefined && FileName !== "") {
        //     fileName = FileName;
        // }
        // url = url + "fileName=" + fileName;
        console.log(kk)
        console.log(url)
            // for (let j = 0; j < kk.length; j++) {
            // let fileUrl = kk[j];
            // console.log(fileUrl)
        //     let pushData = "";
        //     pushData = that.make();
        //     let pushURL = "SearchPet/addSearchPet";   
        // call.upFile(url, kk, "img", function(res) {
        //         console.log(res.date);
        //     }, function(e) {
        //         console.log(e)
        //     }, 0,pushData,pushURL)
            // }
           let data = {
                url: url,//这里是你要上传的服务器接口
                path: kk//这里是你最开始定义的图片数组
              }
            call.uploadImage(data);
        console.log("ss")
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },
    admiin1: function() {

    },
    submit: function() {
        let hh = this;
        hh.up();
    },

    make: function() {
        let FileName = "";
        FileName = wx.getStorageSync('fileName');
        let admin = this;
        let SearchM = {
            "lose_detailed_area": "某街区某小区某栋楼",
            // "lose_time": "2019年9月9日 20:00",

// lose_city_area: "福州",
// lose_county_area: "鼓楼区",
// lose_detailed_area: "百度新华街",
// publisher_phone: "17687551157",
// search_pet_age: "2月25天",
// search_pet_category: "喵星人",
// search_pet_message: "就是很吊？很吊就对了",
// search_pet_name: "李晓静",
// search_pet_sex: "女孩子",
// search_pet_varieties: "埃及猫",
// special_advice: "就是这么吊？？？？",
        };
        SearchM.special_advice = admin.data.special_advice;
        SearchM.search_pet_name = admin.data.search_pet_name;
        SearchM.search_pet_category = admin.data.checkValue;
        SearchM.search_pet_varieties = admin.data.value;
        // SearchM.search_pet_age = admin.data.search_pet_age;
        SearchM.search_pet_sex = admin.data.checkValue_sex;
        SearchM.lose_county_area = admin.data.lose_county_area;
        SearchM.search_pet_message = admin.data.search_pet_message;
        SearchM.lose_city_area = admin.data.lose_city_area;
        SearchM.lose_detailed_area = admin.data.lose_detailed_area;
        // SearchM.lose_time = admin.data.lose_time;
        SearchM.publisher_phone = admin.data.publisher_phone;
        SearchM.search_pet_age = "2月25天";
        SearchM.file_name = FileName;
        console.log(SearchM)
        return SearchM;
        // // this.sendSearch(SearchM);
    },
    search_pet_name: function(e) {
        this.setData({
            search_pet_name: e.detail.value
        })
    },
    search_pet_age: function(e) {
        this.setData({
            search_pet_age: e.detail.value
        })
    },
    // search_pet_contact: function (e) {
    //   this.setData({
    //     search_pet_contact: e.detail.value
    //   })
    // },
    search_pet_message: function(e) {
        this.setData({
            search_pet_message: e.detail.value
        })
    },
    search_pet_area: function(e) {
        this.setData({
            search_pet_area: e.detail.value
        })
    },
    publisher_phone: function(e) {
        this.setData({
            publisher_phone: e.detail.value
        })
    },
    lose_time: function(e) {
        this.setData({
            lose_time: e.detail.value
        })
    },
    lose_city_area: function(e) {
        this.setData({
            lose_city_area: e.detail.value
        })
    },
    lose_county_area: function(e) {
        this.setData({
            lose_county_area: e.detail.value
        })
    },
    special_advice: function(e) {
        this.setData({
            special_advice: e.detail.value
        })
        console.log(this.data.special_advice)
    },
    lose_detailed_area: function(e) {
        this.setData({
            lose_detailed_area: e.detail.value
        })
    }


    /**
     * 用户点击右上角分享
     */


})